home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Clocks / DockClock / Source / Distributer.m < prev    next >
Text File  |  1992-12-19  |  5KB  |  204 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "Distributer.h"
  5. #import "Clock.h"
  6.  
  7. #import <appkit/Window.h>
  8. #import <appkit/Application.h>
  9. #import <appkit/Button.h>
  10. #import <appkit/Matrix.h>
  11. #import <defaults/defaults.h>
  12. #import <appkit/OpenPanel.h>
  13. #import <stdlib.h>
  14. #import <string.h>
  15.  
  16. #define SECONDS 0
  17. #define MILITARY 1
  18. #define CHIME 2
  19. #define BUTTON 3
  20. #define SET 4
  21. #define BEZIER 5
  22.  
  23. #define DEFNAME "DockClock"
  24.  
  25. static NXDefaultsVector ClockDefaults = {
  26.     {"Type", "1"},
  27.     {"Seconds", "0"},
  28.     {"Military", "0"},
  29.     {"Chime", "0"},
  30.     {"ChimeFile",""},
  31.     {"Bezier","0"},
  32.     {NULL}
  33. };
  34.  
  35. char chimeFile[255];
  36.  
  37. @implementation Distributer
  38.  
  39. - showPreferences:sender
  40. {
  41.     if (!PreferencePanel) {
  42.     [NXApp loadNibSection:"Preferences.nib" owner:self withNames:NO];
  43.     }
  44.     [PreferencePanel makeKeyAndOrderFront:sender];
  45.  
  46.     if (!buttonView) {
  47.     buttonView = [[Clock alloc] init];
  48.     [TypeButton addSubview:buttonView];
  49.     }
  50.     [buttonView setType:[iconView getType]];
  51.     [buttonView setSeconds:[iconView getSeconds]];
  52.     [buttonView setMilitary:[iconView getMilitary]];
  53.     [buttonView setChime:[iconView getChime]];
  54.     [buttonView setBezier:[iconView getBezier]];
  55.     [buttonView setUpIcon];
  56.     [buttonView  display];
  57.     if ([iconView getSeconds]) [SwitchMatrix selectCellWithTag:SECONDS];
  58.     if ([iconView getMilitary]) [SwitchMatrix selectCellWithTag:MILITARY];
  59.     if ([iconView getChime]) [SwitchMatrix selectCellWithTag:CHIME];
  60.     if ([iconView getBezier]) [SwitchMatrix selectCellWithTag:BEZIER];
  61.     [chimeFileField setStringValue:chimeFile];
  62.  
  63.     return self;
  64. }
  65.  
  66. - appDidInit:sender
  67. {
  68.     int Cflag;
  69.     char *chimeTmp;
  70.  
  71.     iconView = [[Clock alloc] init];
  72.     [[NXApp appIcon] setContentView:iconView];
  73.  
  74.     // Get everything from the defaults database
  75.     NXRegisterDefaults(DEFNAME,ClockDefaults);
  76.  
  77.     [iconView setType:atof(NXGetDefaultValue(DEFNAME,"Type"))];
  78.     [iconView setSeconds:atof(NXGetDefaultValue(DEFNAME,"Seconds"))];
  79.     [iconView setBezier:atof(NXGetDefaultValue(DEFNAME,"Bezier"))];
  80.     [iconView setMilitary:atof(NXGetDefaultValue(DEFNAME,"Military"))];
  81.  
  82.     chimeTmp = (char *) NXGetDefaultValue(DEFNAME,"ChimeFile");
  83.     strcpy(chimeFile,chimeTmp);        
  84.  
  85.     if ((Cflag = atof(NXGetDefaultValue(DEFNAME,"Chime"))) == 1) {
  86.     if (chimeFile[0] == '\0') [iconView setChime:0];
  87.     else {
  88.         [iconView setChime:1];
  89.         [iconView setChimeFile:chimeFile];
  90.     }
  91.     }
  92.  
  93.     [iconView display];
  94.  
  95.     return self;
  96. }
  97.  
  98. - showInfo:sender
  99. {
  100.     if (!InfoPanel) {
  101.     [NXApp loadNibSection:"Info.nib" owner:self withNames:NO];
  102.     }
  103.     [InfoPanel makeKeyAndOrderFront:sender];
  104.  
  105.     return self;
  106. }
  107.  
  108. - changePref:sender
  109. {
  110.     int Cflag;
  111.     int sw;
  112.     id OP;
  113.     char tmp[4];
  114.     const char *ftypes[2] = {"snd",NULL};
  115.  
  116.     sw = [[sender selectedCell] tag];
  117.     switch(sw) {
  118.     case SECONDS:
  119.         [buttonView setSeconds:[[sender findCellWithTag:sw] state]];
  120.         sprintf(tmp,"%d",[buttonView getSeconds]);
  121.         NXWriteDefault(DEFNAME,"Seconds",tmp);
  122.         break;
  123.     case MILITARY:
  124.         [buttonView setMilitary:[[sender findCellWithTag:sw] state]];
  125.         sprintf(tmp,"%d",[buttonView getMilitary]);
  126.         NXWriteDefault(DEFNAME,"Military",tmp);
  127.         break;
  128.     case BEZIER:
  129.         [buttonView setBezier:[[sender findCellWithTag:sw] state]];
  130.         sprintf(tmp,"%d",[buttonView getMilitary]);
  131.         NXWriteDefault(DEFNAME,"Bezier",tmp);
  132.         break;
  133.     case CHIME:
  134.         Cflag = [[sender findCellWithTag:sw] state];
  135.         if (Cflag && (*chimeFile == '\0')) {
  136.         NXRunAlertPanel("Alert","No chime sound file has been selected.  Please select one and choose this option again.",
  137.                     NULL,NULL,NULL);
  138.         [buttonView setChime:0];
  139.         [[sender findCellWithTag:CHIME] setState:0];
  140.         break;
  141.         }
  142.         if (Cflag)
  143.         [buttonView setChimeFile:chimeFile];
  144.         sprintf(tmp,"%d",Cflag);
  145.         NXWriteDefault(DEFNAME,"Chime",tmp);
  146.         break;
  147.     case BUTTON:
  148.         [buttonView setType:[buttonView getType]+1];
  149.         [buttonView setSeconds:atof(NXGetDefaultValue(DEFNAME,"Seconds"))];
  150.         break;
  151.     case SET:
  152.         OP = [OpenPanel new];
  153.         if ([OP runModalForTypes:ftypes]) {
  154.         sprintf(chimeFile,"%s/%s",[OP directory],*[OP filenames]);
  155.         [chimeFileField setStringValue:chimeFile];
  156.         NXWriteDefault(DEFNAME,"ChimeFile",chimeFile);
  157.         [buttonView setChimeFile:chimeFile];
  158.         }
  159.         break;
  160.     }
  161.     [buttonView display];   // Force a display
  162.     return self;
  163. }
  164.  
  165. - appDidHide:sender
  166. {
  167.     char tmp[4];
  168.  
  169.     // All of these if's are pretty dumb, but I don't really want to change
  170.     // anything unless I know the preferences have changed.
  171.  
  172.     if (buttonView && ([buttonView getType] != [iconView getType])) {
  173.     sprintf(tmp,"%d",[buttonView getType]);
  174.     NXWriteDefault(DEFNAME,"Type",tmp);    
  175.     [iconView setType:[buttonView getType]];
  176.     }
  177.     if (buttonView) {
  178.     [iconView setSeconds:[buttonView getSeconds]];
  179.     [iconView setMilitary:[buttonView getMilitary]];
  180.     [iconView setChime:[buttonView getChime]];    
  181.     [iconView setChimeFile:chimeFile];
  182.     [iconView setBezier:[buttonView getBezier]];
  183.     }
  184.  
  185.     [InfoPanel close];                // These guys have the "free when closed" flag set in IB
  186.     InfoPanel = [InfoPanel free];
  187.  
  188.     [PreferencePanel close];
  189.     PreferencePanel = [PreferencePanel free];  
  190.  
  191.     buttonView = nil;    // the Preference panel may free this but I want it nil
  192.  
  193.     [iconView display];
  194.     return self;
  195. }
  196.  
  197. - appDidResignActive:sender
  198. {    
  199.     [self appDidHide:self];
  200.     return self;
  201. }
  202.  
  203. @end
  204.